var {
 getEventInfo,
 updateEvent
} = require('../../utils/api');
const methods = require('../../utils/methods');
const app = getApp();

Page({

 data: {
  imgUrl: [],
  uname:'',
  // tab切换
  info: {},
  areas: [],
  types: [],
  levels: [],
  textvalues: '',
  eventId:'',
  eventStatus:'',
 },

 onLoad(option) {
  let _this = this;
  console.log('传过来的id===', option.id)


  _this.setData({
   areas: app.globalData.areaArray,
   types: app.globalData.typeArray,
   levels: app.globalData.levelArray,
   eventId:option.id,
   uname:app.globalData.userInfo.name
  })
  getEventInfo(option.id).then((res) => {
   let img = res[1].fileUrl.split(',');

   //数据处理
   let area = res[1].eventArea;
   let type = res[1].eventType;
   let level = res[1].eventLevel;


   area = (_this.data.areas.find(t => t.value == area)).label;
   type = (_this.data.types.find(t => t.value == type)).label
   level = (_this.data.levels.find(t => t.value == level)).label
   console.log('1=====', area, type, level);

   _this.setData({
    info: res[1],
    imgUrl: img,
    area,
    type,
    level,
    eventStatus:res[1].eventStatus,
    textvalues:res[1].eventResult,
   }, () => {
   })
  })


 },
 resultInput(e) {
  console.log('====', e.detail.value)
  this.setData({
   textvalues: e.detail.value
  })
 },

 enterIn() {
  let _this = this;
  if(!_this.data.textvalues){
   methods.showToast('结果不能为空');
   return;
  }
   console.log({
    eventResult: _this.data.textvalues,
    id: app.globalData.id
   });
   updateEvent({
    eventResult: _this.data.textvalues,
    id: _this.data.eventId,
    eventStatus:_this.data.textvalues ? 3 : 2
   }).then((res) => {
    console.log('处理结果===', res);
    if(res[0]==200){
     wx.navigateBack({
       delta: 2,
     })
    }



   })

 }
})